from pyprocessing import run, background, size
from threading import Thread
from processing.model.processing_cpu import ProcessingCPU
from processing.model.root import Root
from processing.model.processing_kernel import ProcessingKernel
from processing.model.ready_queue import ReadyQueue
from processing.model.io_queue import IOQueue
from processing.shape.color import color


class Engine(Thread):
    
    DELAY = 0.5
    CREATEING_DELAY = 0.01
    
    def __init__(self):
        Thread.__init__(self)
        self.__cpu    = ProcessingCPU()
        self.__kernel = ProcessingKernel()
        self.__ready  = ReadyQueue()
        self.__io  = IOQueue()
        self.__root = self.create_component_three()
        self.__background = color.green
        self.__delay = Engine.DELAY
        self.__creating_delay = Engine.CREATEING_DELAY
        
    def create_component_three(self):
        return Root().add(
                self.cpu).add(
                self.kernel).add(
                self.io).add(
                self.ready)
    
    def setup(self):
        size(800,600,caption="Kernel processing")
        
    def update(self):
        self.root.update()
            
    def draw(self):
        background(*self.background)
        self.root.draw()

    def run(self):
        run()
        
    @property
    def delay(self):
        return self.__delay
    
    @property
    def creating_delay(self):
        return self.__creating_delay
    
    @property
    def cpu(self):
        return self.__cpu
    
    @property
    def kernel(self):
        return self.__kernel
    
    @property
    def ready(self):
        return self.__ready
     
    @property
    def io(self):
        return self.__io
    
    @property
    def root(self):
        return self.__root

   
    @property
    def background(self):
        return self.__background    
      
    @background.setter
    def background(self, value):
        self.__background = value